﻿<ResourceDictionary xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    xmlns:Controls="clr-namespace:PSE.Framework.UI.Controls.SmartClient;assembly=PSE.Framework.UI.Controls">

    <!--BEGIN TREEVIEW-->
    <DataTemplate x:Key="DataTemplateDefaultTreeView">
        <Controls:Label Content="{Binding}" Padding="0,0,0,3.5" HorizontalAlignment="Left" Width="Auto" Height="21" VerticalAlignment="Center" IsEnabled="{TemplateBinding IsEnabled}"/>
    </DataTemplate>

    <Style TargetType="{x:Type Controls:TreeView}">
        <Setter Property="ItemTemplate" Value="{StaticResource DataTemplateDefaultTreeView}"/>
        <Setter Property="Template">
            <Setter.Value>
                <ControlTemplate TargetType="{x:Type Controls:TreeView}">
                    <Border SnapsToDevicePixels="True" BorderBrush="{DynamicResource BrushTreeViewBorder}" BorderThickness="1" CornerRadius="3" Background="{DynamicResource BrushTreeViewBackground}">
                        <ScrollViewer Focusable="False" SnapsToDevicePixels="{TemplateBinding SnapsToDevicePixels}" Background="{DynamicResource BrushTreeViewBackground}" Padding="1" CanContentScroll="false" HorizontalScrollBarVisibility="Auto" VerticalScrollBarVisibility="Auto" Margin="1">
                            <ItemsPresenter/>
                        </ScrollViewer>
                    </Border>
                </ControlTemplate>
            </Setter.Value>
        </Setter>
    </Style>

    <Style x:Key="ControlTreeViewToggleButton" TargetType="{x:Type ToggleButton}">
        <Setter Property="Focusable" Value="False"/>
        <Setter Property="Width" Value="19"/>
        <Setter Property="Height" Value="13"/>
        <Setter Property="Template">
            <Setter.Value>
                <ControlTemplate TargetType="{x:Type ToggleButton}">
                    <Border Width="19" Height="13" Background="Transparent">
                        <Border x:Name="Border" Width="9" Height="9" SnapsToDevicePixels="true" BorderBrush="{DynamicResource BrushTreeViewToggleButtonBorder}" BorderThickness="1" CornerRadius="1" Background="{DynamicResource BrushTreeViewToggleButtonBackground}">
                            <Path Margin="1,1,1,1" x:Name="ExpandPath" Data="M 0 2 L 0 3 L 2 3 L 2 5 L 3 5 L 3 3 L 5 3 L 5 2 L 3 2 L 3 0 L 2 0 L 2 2 Z" Fill="{DynamicResource BrushTreeViewToggleButtonIconBackground}"/>
                        </Border>
                    </Border>
                    <ControlTemplate.Triggers>
                        <Trigger Property="IsChecked" Value="True">
                            <Setter Property="Data" TargetName="ExpandPath" Value="M 0 2 L 0 3 L 5 3 L 5 2 Z"/>
                        </Trigger>
                        <Trigger Property="IsEnabled" Value="False">
                            <Setter Property="BorderBrush" Value="{DynamicResource BrushTreeViewToggleButtonBorderDisabled}" TargetName="Border"/>
                            <Setter Property="Fill" Value="{DynamicResource BrushTreeViewToggleButtonIconBorderDisabled}" TargetName="ExpandPath"/>
                        </Trigger>
                    </ControlTemplate.Triggers>
                </ControlTemplate>
            </Setter.Value>
        </Setter>
    </Style>
    
    <Style TargetType="{x:Type Controls:TreeViewItem}">
        <Setter Property="Background" Value="Transparent"/>
        <Setter Property="Padding" Value="5,0"/>
        <Setter Property="Template">
            <Setter.Value>
                <ControlTemplate TargetType="{x:Type Controls:TreeViewItem}">
                    <Grid>
                        <Grid.ColumnDefinitions>
                            <ColumnDefinition MinWidth="19" Width="Auto"/>
                            <ColumnDefinition Width="Auto"/>
                            <ColumnDefinition Width="*"/>
                        </Grid.ColumnDefinitions>
                        <Grid.RowDefinitions>
                            <RowDefinition Height="21"/>
                            <RowDefinition/>
                        </Grid.RowDefinitions>
                        <ToggleButton x:Name="Expander" Style="{StaticResource ControlTreeViewToggleButton}" ClickMode="Press" IsChecked="{Binding Path=IsExpanded, RelativeSource={RelativeSource TemplatedParent}}"/>
                        <Border x:Name="Bd" SnapsToDevicePixels="true" Grid.Column="1" Padding="5,0">
                            <ContentPresenter ContentTemplate="{Binding Path=ItemTemplate, RelativeSource={RelativeSource FindAncestor, AncestorType={x:Type Controls:TreeView}}}" HorizontalAlignment="{TemplateBinding HorizontalContentAlignment}" x:Name="PART_Header" SnapsToDevicePixels="{TemplateBinding SnapsToDevicePixels}" ContentSource="Header" Style="{DynamicResource ControlFont}" VerticalAlignment="Center"/>
                        </Border>
                        <ItemsPresenter x:Name="ItemsHost" Grid.Column="1" Grid.ColumnSpan="2" Grid.Row="1" Style="{DynamicResource ControlFont}" VerticalAlignment="Top" Margin="0"/>
                    </Grid>
                    <ControlTemplate.Triggers>
                        <Trigger Property="IsExpanded" Value="False">
                            <Setter Property="Visibility" TargetName="ItemsHost" Value="Collapsed"/>
                        </Trigger>
                        <Trigger Property="HasItems" Value="False">
                            <Setter Property="Visibility" TargetName="Expander" Value="Hidden"/>
                        </Trigger>
                        <Trigger Property="IsSelected" Value="true">
                            <Setter Property="CornerRadius" TargetName="Bd" Value="3"/>
                            <Setter Property="Background" Value="{DynamicResource BrushTreeViewItemBackgroundSelected}" TargetName="Bd"/>
                        </Trigger>
                        <MultiTrigger>
                            <MultiTrigger.Conditions>
                                <Condition Property="IsSelected" Value="True"/>
                                <Condition Property="IsEnabled" Value="False"/>
                            </MultiTrigger.Conditions>
                            <Setter Property="Background" Value="{DynamicResource BrushTreeViewItemBackgroundSelectedUnfocused}" TargetName="Bd"/>
                        </MultiTrigger>
                        <MultiTrigger>
                            <MultiTrigger.Conditions>
                                <Condition Property="IsSelected" Value="True"/>
                                <Condition Property="IsSelectionActive" Value="False"/>
                            </MultiTrigger.Conditions>
                            <Setter Property="Background" Value="{DynamicResource BrushTreeViewItemBackgroundSelectedUnfocused}" TargetName="Bd"/>
                        </MultiTrigger>
                    </ControlTemplate.Triggers>
                </ControlTemplate>
            </Setter.Value>
        </Setter>
    </Style>
    <!--END TREEVIEW-->
</ResourceDictionary>